import { Component, OnInit } from '@angular/core';
import {Company} from '../../entity/company';
import {Talent} from '../../entity/talent';
import {RegisterService} from '../../service/register.service';
import * as $ from 'jquery';

// 注册模块
@Component({
  selector: 'app-register',
  templateUrl: './register.component.html',
  styleUrls: ['./register.component.css', '../login/login.component.css']
})
export class RegisterComponent implements OnInit {
  company: Company = new Company();
  talent: Talent = new Talent();
  flag = true;
  constructor(
    public registerService: RegisterService
  ) { }

  ngOnInit() {
    $('.screenbg ul li').each(function() {
      $(this).css('opacity', '0');
    });
    $('.screenbg ul li:first').css('opacity', '1');
    let index = 0;
    let t;
    let li = $('.screenbg ul li');
    let number = li.length;
    function change() {
      li.css('visibility', 'visible');
      li.eq(index).siblings().animate({opacity: 0}, 3000);
      li.eq(index).animate({opacity: 1}, 3000);
    }
    function show() {
      index = index + 1;
      if (index <= number - 1) {
        change();
      } else {
        index = 0;
        change();
      }
    }
    t = setInterval(show, 8000);
    // 根据窗口宽度生成图片宽度
    let width = $(window).width();
    $('.screenbg ul img').css('width', width + 'px');
  }
  addCompany() {
    // debugger
    this.registerService.addCompany(this.company);
  }
  addTalent() {
    this.registerService.addTalent(this.talent);
  }
  setFlag() {
    this.flag = !this.flag;
  }
}
